package io.mft.api.domain;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import io.mft.commons.function.response.kv.KVMap;
import io.mft.commons.util.Unique;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@JsonInclude(Include.NON_DEFAULT)
public class InputParameter implements Unique,ActualKeyInitor,Serializable{
	
	 
	        /**
	 * @说明：TODO
	 * @字段名称 serialVersionUID
	        */  
	    
	private static final long serialVersionUID = -6805669569441072739L;

	public static enum InputParameterDataType{
		json,jsonArray,string,Int,Long;
	}
	private String key;
	private boolean require;
	private boolean primaryKey;
	private String primaryKeyValueAutogenerateType="input";
	private String name;
	private InputParameterDataType dataType=InputParameterDataType.string;
	@JsonInclude(Include.NON_EMPTY) 
	private String example="";
	@JsonIgnore
	private String actualKey;
	@JsonInclude(Include.NON_EMPTY) 
	private String defaultValue="";
	private boolean unique=false;
	@JsonInclude(Include.NON_NULL) 
	private InputParameterJsonFormat jsonFormat;
	@JsonInclude(Include.NON_EMPTY) 
	private String condition="";
	@JsonInclude(Include.NON_EMPTY) 
	private String conditionType="";
	@JsonInclude(Include.NON_EMPTY) 
	private String remark="";
	@JsonInclude(Include.NON_EMPTY) 
	private String mapping="";
	
	@Override
	public String uniqueId() {
		String dt=ObjectUtil.isEmpty(dataType)?"":dataType.name();
		String ukey=key+"-"+require+"-"+dt+"-"+defaultValue+"-"+unique+"-"+conditionType+"-"+condition;
		if (ObjectUtil.isNotNull(jsonFormat)) {
			ukey=ukey+"-"+jsonFormat.uniqueId();
		}
		return ukey;
	}
	
	@Override
	public KVMap initActualKey(boolean toUnderlineCase) {
		KVMap map=new KVMap();
		if (jsonFormat!=null) {
			KVMap m=jsonFormat.initActualKey(toUnderlineCase);
			map.putAll(m);
		}
		if (toUnderlineCase) {
			String key=StrUtil.toUnderlineCase(getKey());
			setActualKey(key);
			map.set(getKey(), key);
		}else {
			setActualKey(getKey());
			map.set(getKey(), getKey());
		}
		return map;
	}
}
